Fixes Bug in MongoDBStorage with Entity in Entities #968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Description of Changes
This PR fixes an issue with MongoDB backend where adding or updating SubmodelElements within an
Entityelement fails. The root cause was thatMongoFilterBuilder.parse()always used"value"as the key for nested elements, butEntitystores its children in"statements"according to the AAS metamodel.Changes made:
MongoFilterBuilder.java:
parse()method to accept an optional list of parentSubmodelElementobjectsEntityand use"statements"instead of"value"for the MongoDB update pathMongoDbSubmodelOperations.java:
getParentElements()helper method that traverses the idShortPath and collects all parent SubmodelElementsupdateSubmodelElement()to callgetParentElements()before building the MongoDB filter, providing type information to correctly determine the pathRelated Issue
Fixes issue where MongoDB write operations fail with error:
BaSyx Configuration for Testing
Standard MongoDB backend configuration for Submodel Service:
AAS Files Used for Testing
Any Submodel containing nested Entity elements can be used for testing. Example:
{ "idShort": "TestSubmodel", "id": "http://example.org/submodel", "submodelElements": [ { "modelType": "Entity", "idShort": "OuterEntity", "entityType": "CoManagedEntity", "statements": [ { "modelType": "Entity", "idShort": "InnerEntity", "entityType": "CoManagedEntity", "statements": [] } ] } ] }Test scenario:
/submodels/{submodelId}/submodel-elements/{entityIdShort}Additional Information
SubmodelElementCollectionandSubmodelElementListremains unchangedgetParentElements()method performs multiple database queries to traverse the path, which could be optimized in the future if performance becomes a concernbuildAggregationOperations) already handled bothvalueandstatementscorrectly using OR conditions, so no changes were needed there